package com.jiufen.Service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jiufen.Mapper.OperateLogMapper;
import com.jiufen.Pojo.GenericQueryParam;
import com.jiufen.Pojo.OperateLog;
import com.jiufen.Pojo.PageResult;
import com.jiufen.Service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private OperateLogMapper operateLogMapper;

    @Override
    public PageResult<OperateLog> getLogPage(GenericQueryParam genericQueryParam) {
        //开启pageHelp
        PageHelper.startPage(genericQueryParam.getPage(), genericQueryParam.getPageSize());


        //获取结果
        List<OperateLog> operateLogs = operateLogMapper.queryLogByPage();
        log.debug("查询出的日志信息为：{}", operateLogs);

        //处理为page
        Page<OperateLog> operateLogPage = (Page<OperateLog>) operateLogs;

        //封装PageResult
        PageResult<OperateLog>  pageResult = new PageResult<OperateLog>(operateLogPage.getTotal(), operateLogPage.getResult());


        return pageResult;
    }
}
